﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Script.Serialization;

namespace Extension
{
 
        public static class ExtensionMethods
        {
            public static string GetJson(this String auth)
            {
            var auths = auth.Split('.');
            byte[] bytes = Jose.Base64Url.Decode(auths[1]);

            Console.WriteLine(bytes.Length);
            var json = Encoding.UTF8.GetString(bytes);
            return json;
        }
        public static EmployeeInfo GetEmployeeUserObject(string auth)
        {
            var userJson = GetJson(auth);
            return JsonStringToObj<EmployeeInfo>(userJson);
        }
        public static ClientInfo GetClientUserObject(string auth)
        {
            var userJson = GetJson(auth);
            return JsonStringToObj<ClientInfo>(userJson);
        }
        private static ObjType JsonStringToObj<ObjType>(string JsonString) where ObjType : class
        {
            JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();
            ObjType s = jsonSerializer.Deserialize<ObjType>(JsonString);
            return s;
        }
    }
    
}
